package com.udi.project.business.local.gs1.thread;


import com.udi.common.exception.base.BaseException;
import com.udi.common.utils.spring.SpringUtils;
import com.udi.project.business.local.gs1.domain.Gs1Data;
import com.udi.project.business.local.gs1.mapper.Gs1GenerateMapper;
import com.udi.project.business.utils.redis.RedisUtils;
import lombok.SneakyThrows;

import java.util.List;

/**
 * @author Admin
 * GS1持久化
 */
public class Gs1Thread extends Thread{


    private RedisUtils redisUtils;
    private Gs1GenerateMapper gs1GenerateMapper;

    public  Gs1Thread() {
        this.redisUtils = SpringUtils.getBean(RedisUtils.class);
        this.gs1GenerateMapper = SpringUtils.getBean(Gs1GenerateMapper.class);
    }

    @SneakyThrows
    @Override
    public void run() {
        List<Gs1Data> gs1Data = (List<Gs1Data>) redisUtils.get("data");
        int ove = gs1GenerateMapper.insertGs1(gs1Data);
        if(ove == 0){
            redisUtils.lSet("ThreadHint","{\"messg\":\"UDI持久化失败\",\"TypeNumber\":5003},");
            throw new Exception("UDI持久化失败");
        }else {redisUtils.del("GS1key","data");}
    }
}
